package com.jshan.utils;

import com.jshan.service.SysServerService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetSocketAddress;
import java.net.Socket;

@Component
@RequiredArgsConstructor
public class ServerMonitorUtils {

    private final SysServerService serverService;
    private static final Logger log = LoggerFactory.getLogger(ServerMonitorUtils.class);

    /**
     * 检查服务器是否在线
     */
    public boolean isServerOnline(String ip, int port) {
        try (Socket socket = new Socket()) {
            socket.connect(new InetSocketAddress(ip, port), 10000);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
